<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let s = "A man, a plan, a canal: Panama"
        //let fitstring = s.toLowerCase().match(/[A-Za-z0-9]+/g);
        //let newstring = "" + fitstring
        //console.log(fitstring);
        //let newstring = fitstring.join("")
        let newstring = s.toLowerCase().match(/[\W_]+/g)
        let sure = ''
        console.log(newstring);
        if (newstring.length > 1) {
            if (newstring.length % 2 == 0) {
                for (let i = 0; i <= (newstring.length / 2) - 1; i++) {
                    for (let j = newstring.length - 1; j >= (newstring.length / 2); j--) {
                        if (newstring[i] != newstring[j]) {
                            sure = 'false'
                        }
                    }
                }
            } else {
                for (let i = 0, j = newstring.length - 1; i <= ((newstring.length - 1) / 2) - 1, j >= (newstring.length / 2) + 1; i++, j--) {
                    if (newstring[i] != newstring[j]) {
                        console.log(newstring[i], newstring[j])
                        sure = 'false'
                    }
                }
            }
            console.log(sure);
            if (sure == 'false') {
                console.log('false');
            } else {
                console.log('true');
            }
        } else {
            console.log("true");
        }

    </script>
</body>

</html>